# -*- coding: utf-8 -*-
"""
@Time : 2024/10/17 18:00
@Author : ChenXiaoliang
@Email : middlegod@sina.com
@File : read_config.py
"""
import yaml
import logging

LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename='monitor.log', level=logging.INFO, filemode='a', format=LOG_FORMAT)
logger = logging.getLogger()


def load_yaml(filename):
    try:
        with open(filename, 'r', encoding='utf-8') as stream:
            docs = yaml.load_all(stream, Loader=yaml.FullLoader)
            param_dict = dict()
            for doc in docs:
                for k, v in doc.items():
                    param_dict[k] = v
            return param_dict
    except Exception as e:
        print(f"读取配置文件失败\n{e}")
        logger.error(f"读取配置文件失败\n{e}")


if __name__ == '__main__':
    print(load_yaml('../config_monitor.yaml'))
    print(type(load_yaml('../config_monitor.yaml').get('email').get('receiver')))
